home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt87ibm.arc
/
SAGAN.ARC
/
MDRIVER.ASM
next >
Wrap
Assembly Source File
|
1987-06-17
|
4KB
|
210 lines
;
;
;
; ====================== CODE SEGMENT DEFN =======================
;
CSEG segment public para 'code'
;
; Set to MICROSOFT = 0 to make mousesys sample program
; Set to MICROSOFT = 1 to make microsoft sample program
;
MICROSOFT = 0
;
ORG 0
;
ZERO LABEL WORD
;
ORG 100h ; For sample program only
;
;
ASSUME CS:CSEG, DS:CSEG, ES:NOTHING, SS:NOTHING
;
START:
JMP SAMPLECODE
;
; These are the available functions:
;
; function 0 = initialize mouse
; function 1 = return button status
; function 2 = return relative motion
; function 3 = de-initialize mouse
; function 4 = return current serial port
;
IF MICROSOFT
INCLUDE MICROSOF.ASM
ELSE
INCLUDE MOUSESYS.ASM
ENDIF
;
VIDEO = 10H
;
MAXX DW 80
MAXY DW 22
MYX DW 0
MYY DW 0
MBSTAT DB 0FFH
CVM DB 0
;
BUT1MES DB 'Button one: $'
BUT2MES DB 'Button two: $'
BUT3MES DB 'Button three:$'
PRESMES DB 'pressed $'
RELMES DB 'released$'
ERRMES DB 'Mouse or Mouse software not installed$'
;
ERR_NODEVICE:
MOV DX,OFFSET ERRMES
CALL PRINT
JMP EXIT_ROUTINE
;
SAMPLECODE:
PUSH CS
POP DS
MOV AH,0FH
INT VIDEO ; Get current video mode
MOV CVM,AL ; Save current video mode
MOV BYTE PTR MAXX,AH ; store maximum cursor position
SUB AH,AH
INT VIDEO ; Clear screen
MOV DH,BYTE PTR MAXY ; Row 22, column 0
SUB DL,DL
PUSH DX
CALL SET_CURSOR
MOV DX,OFFSET BUT1MES
CALL PRINT
POP DX
INC DH
PUSH DX
CALL SET_CURSOR
MOV DX,OFFSET BUT2MES
CALL PRINT
POP DX
INC DH
CALL SET_CURSOR
MOV DX,OFFSET BUT3MES
CALL PRINT
;
MOV BX,4
CALL ENTRY ; Serial port in Ax
SUB BX,BX
CALL ENTRY ; Initialize mouse
OR AL,AL ; If al = zero then an error occured
JZ ERR_NODEVICE
SCLOOP:
MOV BX,2
CALL ENTRY
MOV CX,5 ; scale x coordinate
CWD
IDIV CX
ADD AX,MYX ; My x cursor position
JNS SCLOOP1
MOV AX,MAXX ; wrap to right
DEC AX
SCLOOP1:
CMP AX,MAXX
JNG SCLOOP2
SUB AX,AX ; Wrap to left
SCLOOP2:
MOV MYX,AX ; Save new x
MOV AX,BX ; get delta y
CWD
IDIV CX
ADD AX,MYY ; My y cursor position
JNS SCLOOP25
MOV AX,MAXY ; Wrap to bottom of screen
DEC AX
SCLOOP25:
CMP AX,MAXY
JNG SCLOOP3
SUB AX,AX ; Wrap to top
SCLOOP3:
MOV MYY,AX ; Save new y
MOV BX,1
CALL ENTRY
CMP AL,MBSTAT
JE SCLOOP4
MOV MBSTAT,AL
SHR AX,1 ; put button 1 status in carry
MOV DH,BYTE PTR MAXY
MOV DL,15
CALL BUTTONPRINT
SHR AX,1
INC DH
CALL BUTTONPRINT
SHR AX,1
INC DH
CALL BUTTONPRINT
SCLOOP4:
MOV DL,BYTE PTR MYX
MOV DH,BYTE PTR MYY
CALL SET_CURSOR
MOV AH,1
INT 16H ; Keyboard input ?
JZ SCLOOP ; No
SUB AH,AH
INT 16H ; Read key
CMP AL,27 ; <Esc> ?
JZ SCLOOP5
MOV AH,14
INT VIDEO
MOV AH,3
SUB BH,BH
INT VIDEO ; Read cursor position
MOV BYTE PTR MYX,DL
MOV BYTE PTR MYY,DH
JMP SCLOOP
;
SCLOOP5:
MOV BX,3
CALL ENTRY ; Clean up after mouse
;
EXIT_ROUTINE:
MOV AL,CVM
SUB AH,AH
INT VIDEO ; Clear screen
MOV AX,04C00H
INT MSDOS ; bye bye
;
SET_CURSOR:
SUB BH,BH
MOV AH,02
INT VIDEO ; Set cursor position
RET
;
BUTTONPRINT:
PUSH AX
PUSH DX
PUSHF
CALL SET_CURSOR
MOV DX,OFFSET RELMES
POPF
JNC BP2 ; Carry means button pressed
MOV DX,OFFSET PRESMES
BP2:
CALL PRINT
POP DX
POP AX
RET
;
PRINT:
PUSH SI
PUSH BX
MOV SI,DX
MOV BX,3
PRIN1:
LODSB
CMP AL,'$'
JE PRIN2
MOV AH,14
INT VIDEO ; Teletype routine
JMP PRIN1
;
PRIN2:
POP BX
POP SI
RET
;
CSEG ENDS
;
END START